CMAKE_MINIMUM_REQUIRED(VERSION 3.16)
PROJECT(InfantryAutoaim LANGUAGES CXX)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)


SET(CMAKE_CXX_STANDARD 17)
SET(CMAKE_BUILD_TYPE Debug)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DPATH=\"\\\"${PROJECT_SOURCE_DIR}\\\"\"")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D${CMAKE_SYSTEM_NAME}")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -pthread")

FIND_PACKAGE(OpenCV REQUIRED)
FIND_PACKAGE(Threads)
FIND_PACKAGE(Eigen3 REQUIRED)

# MYZ added
FIND_PACKAGE(OpenGL REQUIRED)
FIND_PACKAGE(PkgConfig REQUIRED)
pkg_search_module(GLFW REQUIRED glfw3)

# Display the version information for each library
message("OpenCV version: ${OpenCV_VERSION}")
message("Threads library version: ${CMAKE_THREAD_LIBS_INIT}")
message("Eigen3 version: ${Eigen3_VERSION}")
message("Eigen include path: ${Eigen_INCLUDE_DIRECTORIES}")


message("eigen path ${Eigen_INCLUDE_DIRECTORIES}")
INCLUDE_DIRECTORIES(
	"include/"
	"include/mercure"
	"include/Armor"
	"include/Const"
	"include/Debug"
	"include/Extend"
	"include/ImageProgress"
	"include/Serial"
	"include/Solver"
	"include/Rune"
	"include/serial"
	"include/Logger"
	"include/imgui"
	"include/IMGuiDev"
	"include/implot"
	"include/implot3d"
	"include/Observer"
	${OPENCV_INCLUDE_DIRECTORIES}
	${Eigen_INCLUDE_DIRECTORIES}
	${GLFW_INCLUDE_DIRS}
)


add_subdirectory(
	${CMAKE_CURRENT_SOURCE_DIR}/src/mercure
)

FILE(GLOB_RECURSE sourcefiles "src/*.cpp")


find_library(WIRINGOP_LIB wiringPi)  # 查找 wiringOP 库（它是 wiringPi 的替代库）



ADD_EXECUTABLE(Autoaim  ${sourcefiles})
TARGET_LINK_LIBRARIES(
	Autoaim
	mercure_driver
	${OpenCV_LIBS}

	${WIRINGOP_LIB}
	OpenGL::GL
	${GLFW_LIBRARIES}
	dl
	pthread
)

# ---------------------------------------------------------------
# 如何使用 perf 分析本项目性能：
#
# 1. 确保已安装 perf 工具
#    sudo apt install perf
#
# 2. 编译本项目时保留调试符号（已默认设置 -g）
#    确认 CMAKE_BUILD_TYPE 为 Debug 或 RelWithDebInfo
#
# 3. 使用 perf 采样程序运行过程：
#    perf record ./Autoaim
#
# 4. 查看性能报告：
#    perf report
#
# （可选）生成火焰图：
#    perf script | stackcollapse-perf.pl | flamegraph.pl > flame.svg
#    用浏览器打开 flame.svg 查看
#
# ---------------------------------------------------------------

# 没有启用GPU
# orangepi@orangepi5max:~/Desktop/Szy_RM2022_Infantry/RM2022_lastest-dev/build$ ls /dev/mali*
# /dev/mali0
# orangepi@orangepi5max:~/Desktop/Szy_RM2022_Infantry/RM2022_lastest-dev/build$ glxinfo | grep -i "OpenGL renderer"
# libGL error: glx: failed to create dri3 screen
# libGL error: failed to load driver: rockchip
# libGL error: glx: failed to create dri2 screen
# libGL error: failed to load driver: rockchip
# OpenGL renderer string: llvmpipe (LLVM 15.0.7, 128 bits)